package dongshi.daddy;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Promise;
import io.vertx.core.http.HttpServer;

public class MyVerticle1 extends AbstractVerticle {

    private HttpServer server;

    public void start(Promise<Void> startPromise) {
        server = vertx.createHttpServer().requestHandler(req -> {
            req.response()
                    .putHeader("content-type", "text/plain")
                    .end("Hello from Vert.x!");
        });

        // Now bind the server:
        server.listen(8080, res -> {
            if (res.succeeded()) {
                System.out.println("bind 8080 suc!");
                startPromise.complete();
            } else {
                System.out.println("bind 8080 failed!");
                startPromise.fail(res.cause());
            }
        });
    }


    @Override
    public void start() throws Exception {
        System.out.println("verticle 1 start !!!");
    }
}
